home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************\
- * Header Files
- \******************************************************************************/
-
- #include <Desk.h>
- #include <Events.h>
- #include <Memory.h>
- #include <Menus.h>
- #include <OSUtils.h>
- #include <Resources.h>
- #include <SegLoad.h>
- #include <Traps.h>
- #include <Windows.h>
- #include "ShowCursor.h"
- #include "CursorTkl.h"
- #include "CursWindTkl.h"
- #include "MenuTkl.h"
- #include "ShutDown.h"
- #include "Startup.h"
- #include "WindowTkl.h"
-
-
- /******************************************************************************\
- * Constant Declarations
- \******************************************************************************/
-
- #define susResSelector 0x01 //Selector for suspend/resume event
- #define suspendResumeMessage 1 //Bit for suspend/resume messages
-
- /* True if suspend/resume message is for resume */
- #define suspResIsResume(Message) ((short) ((Message) & 0x00000001L))
-
-
- /******************************************************************************\
- * Function Declarations
- \******************************************************************************/
-
- void main (void);
- void EventLoop (void);
- void DoMouseEvent (EventRecord *);
- void DoKeyEvent (EventRecord *);
- void DoMFEvent (EventRecord *);
-
-
- /******************************************************************************\
- * Global Variables
- \******************************************************************************/
-
- short gApplErr; //Application error
- short gFlags; //Application flags
- WindowPtr gLastWindow; //Active window during last iteration of event loop
- SysEnvRec gEnvirons; //Current Environment
-
-
- /******************************************************************************\
- * Macro Declarations
- \******************************************************************************/
-
- /* Return event record byte which indicates suspend or resume */
- #define app4Selector(EventPtr) (*((unsigned char *) & (EventPtr)->message))
-
- /* Check to see if a trap is available */
- #define trapAvailable(Num,Type) (NGetTrapAddress (Num, Type) != GetTrapAddress \
- (_Unimplemented))
-
-
- #pragma segment Main
- /******************************************************************************\
- * Entry to ShowCursor
- \******************************************************************************/
-
- void
- main ()
- {
- WindowPtr CursWind;
-
- UnloadSeg (Startup);
- MaxApplZone ();
- MoreMasters ();
- MoreMasters ();
- MoreMasters ();
- Startup ();
- UnloadSeg (Startup);
- if (gApplErr == noApplErr)
- {
- CursWind = CreateCursWind ();
- if (gApplErr == noApplErr)
- EventLoop ();
- }
- ShutDown ();
- ExitToShell ();
- }
-
-
- #pragma segment Main
- /******************************************************************************\
- * EventLoop - Main event loop
- *
- * EventLoop is the main event loop. It retrieves events and delegates power
- * to the appropriate handler depending on the type of event.
- \******************************************************************************/
-
- static void
- EventLoop ()
- {
- EventRecord TheEvent; //Usual event record
- short EventOccured; //True if a non-null event occured
- WindowPtr NewFront; //New frontmost window
- short WNEImplemented; //True if WaitNextEvent implemented
- long SleepTime; //Amount of time can sleep under MF
-
- WNEImplemented = (short) trapAvailable (_WaitNextEvent, ToolTrap);
- SleepTime = -1L;
- while (!(gFlags & quitFlag))
- {
- if ((NewFront = FrontWindow ()) != gLastWindow)
- {
- if ((NewFront != (WindowPtr) null) && ((WindowPeek) NewFront)->
- windowKind < 0)
- SleepTime = 10L;
- else
- SleepTime = -1L;
- FixMenuDim ();
- gLastWindow = NewFront;
- }
- FixCursor ();
- if (WNEImplemented)
- EventOccured = WaitNextEvent (everyEvent, &TheEvent, SleepTime,
- (RgnHandle) null);
- else
- {
- SystemTask ();
- EventOccured = GetNextEvent (everyEvent, &TheEvent);
- }
- if (EventOccured)
- {
- switch (TheEvent.what)
- {
- case mouseDown:
- DoMouseEvent (&TheEvent);
- break;
- case keyDown:
- DoKeyEvent (&TheEvent);
- break;
- case updateEvt:
- DoUpdateEvent (&TheEvent);
- break;
- case activateEvt:
- DoActivateEvent ((WindowPeek) TheEvent.message, TheEvent.
- modifiers & (short) activeFlag);
- break;
- case app4Evt:
- DoMFEvent (&TheEvent);
- break;
- default:
- break;
- }
- }
- }
- }
-
-
- #pragma segment Main
- /******************************************************************************\
- * DoMouseEvent - Handle mouse-down event
- *
- * DoMouseEvent handles a mouse-down event by delegating power to the appropriate
- * handler depending on the type of event.
- \******************************************************************************/
-
- static void
- DoMouseEvent (TheEvent)
- EventRecord *TheEvent; //Event from main event loop
- {
- WindowPtr ClickWind; //-> Window that was clicked, if any
- register short PartCode; //Code of part that was clicked
-
- switch (PartCode = FindWindow (TheEvent->where, &ClickWind))
- {
- case inMenuBar:
- DoMenuEvent (MenuSelect (TheEvent->where));
- break;
- case inSysWindow:
- SystemClick (TheEvent, ClickWind);
- break;
- case inContent:
- DoContentEvent (TheEvent, ClickWind);
- break;
- case inDrag:
- DoDragEvent (TheEvent, ClickWind);
- break;
- case inGoAway:
- DoGoAwayEvent (TheEvent, ClickWind);
- break;
- case inZoomIn:
- case inZoomOut:
- DoZoomEvent (TheEvent, ClickWind, PartCode);
- break;
- default:
- break;
- }
- }
-
-
- #pragma segment Main
- /******************************************************************************\
- * DoKeyEvent - Handle key-down event
- *
- * DoKeyEvent handles a key-down event by delegating power to the appropriate
- * handler depending on the type of event.
- \******************************************************************************/
-
- static void
- DoKeyEvent (TheEvent)
- EventRecord *TheEvent; //Event from main event loop
- {
- if (TheEvent->modifiers & cmdKey)
- DoMenuEvent (MenuKey ((char) TheEvent->message));
- }
-
-
- #pragma segment Main
- /******************************************************************************\
- * DoMFEvent - Handle MultiFinder event
- *
- * DoMFEvent handles suspend and resume events.
- \******************************************************************************/
-
- static void
- DoMFEvent (TheEvent)
- EventRecord *TheEvent; //Event from main event loop
- {
- WindowPeek TheWind; //-> Window to activate/deactivate
-
- if (TheEvent->message >> 24 == suspendResumeMessage)
- {
- if (suspResIsResume (TheEvent->message))
- /* Do Resume Stuff */;
- else
- /* Do Suspend Stuff */;
- }
- }
-